﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for MerchantUserDB
/// </summary>
namespace CE.CarInsurance
{
    public class MerchantUserDB
    {
        public Int64 Insert(MerchantUserAccount merchantuser)
        {
            MyDatabase _db = new MyDatabase("GG_MCDBConnectionString");
            Int64 _result = -1;
            string _spName = "sprocMerchantUserInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CEID", merchantuser.CEID);
            _sPara.Add("@UserId", merchantuser.UserId);
            _sPara.Add("@MerchantId", merchantuser.MerchantId);
            _sPara.Add("@Email", merchantuser.Email.ToLower());
            _sPara.Add("@AuthCode", merchantuser.AuthCode);
            _sPara.Add("@AuthSalt", merchantuser.AuthSalt);
            _sPara.Add("@AuthHint", merchantuser.AuthHint);
            _sPara.Add("@UsrTypeId", merchantuser.UserTypeId);
            _sPara.Add("@IsAcceptTC", merchantuser.IsAcceptTC);
            _sPara.Add("@RefCEUserId", merchantuser.RefCEUserID);
            _sPara.Add("@Status", merchantuser.Status);
            _sPara.Add("@Info1", merchantuser.Info1);
            _sPara.Add("@Info2", merchantuser.Info2);
            _sPara.Add("@Info3", merchantuser.Info3);
            _sPara.Add("@Info4", merchantuser.Info4);
            _sPara.Add("@Info5", merchantuser.Info5);
            _sPara.Add("@Info6", merchantuser.Info6);
            _sPara.Add("@Info7", merchantuser.Info7);
            _sPara.Add("@Info8", merchantuser.Info8);
            _sPara.Add("@Info9", merchantuser.Info9);
            _sPara.Add("@Info10", merchantuser.Info10);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public Int64 Delete(Int64 CEID, Int64 RefCEUserId)
        {
            MyDatabase _db = new MyDatabase("GG_MCDBConnectionString");
            Int64 _result = -1;
            string _spName = "sprocMerchantUserDeleteSingleItem";

            SortedList _sPara = new SortedList();
            _sPara.Add("@CEID", CEID);
            _sPara.Add("@RefCEUserId", RefCEUserId);

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DataSet GetUserSearch(string SearchKey, string QuoteRefNo)
        {
            DataSet _ds = new DataSet();
            MyDatabase _db = new MyDatabase("GG_MCDBConnectionString");
            string _spName = "sprocMerchantUserSelectItemList";

            SortedList _spara = new SortedList();

            if (SearchKey.Trim() != "")
            {
                _spara.Add("@SearchKey", SearchKey);
            }
            else
            {
                _spara.Add("@SearchKey", "");
                _spara.Add("@QuoteRefNo", QuoteRefNo);
            }

            _ds = _db.GetDataSet(_spName, _spara);
            return _ds; 
        }

        public DataSet GetUserSearchById(Int64 CEId)
        {
            MyDatabase _db = new MyDatabase("GG_MCDBConnectionString");
            string _spName = "sprocMerchantUserSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@SearchKey", "");
            _spara.Add("@CEID", CEId);

            DataSet _ds = _db.GetDataSet(_spName, _spara);

            return _ds;
        }

    }
}
